package com.ruoyi.waterDistribution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterDistribution.WiCropY;
import com.ruoyi.waterDistribution.vo.WiCropYVo;
import com.ruoyi.waterDistribution.service.IWiCropYService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 年度种植作物Controller
 *
 * @author ps
 * @date 2023-02-16
 */
@RestController
@RequestMapping("/WiCropY")
public class WiCropYController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(WiCropYController.class);

    @Autowired
    private IWiCropYService wiCropYService;

    /**
     * 查询年度种植作物列表
     */
    @RequiresPermissions("distribute:WiCropY:list")
    @GetMapping("/list")
    public TableDataInfo list(WiCropY wiCropY)
    {
        log.info("查询年度种植作物列表 ======= " + wiCropY);
        startPage();
        List<WiCropYVo> list = wiCropYService.selectWiCropYList(wiCropY);
        return getDataTable(list);
    }

    /**
     * 导出年度种植作物列表
     */
    @RequiresPermissions("distribute:WiCropY:export")
    @Log(title = "年度种植作物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiCropYVo wiCropY)
    {
        List<WiCropYVo> list = wiCropYService.selectWiCropYList(wiCropY);
        ExcelUtil<WiCropYVo> util = new ExcelUtil<>(WiCropYVo.class);
        util.exportExcel(response, list, "年度种植作物数据");
    }

    /**
     * 获取年度种植作物详细信息
     */
    @RequiresPermissions("distribute:WiCropY:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        log.info("获取年度种植作物详细信息 ========== " + id);
        return success(wiCropYService.selectWiCropYById(id));
    }

    /**
     * 新增年度种植作物
     */
    @RequiresPermissions("distribute:WiCropY:add")
    @Log(title = "年度种植作物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiCropY wiCropY)
    {
        log.info("新增年度种植作物 ========== " + wiCropY.toString());
        return toAjax(wiCropYService.insertWiCropY(wiCropY));
    }

    /**
     * 修改年度种植作物
     */
    @RequiresPermissions("distribute:WiCropY:edit")
    @Log(title = "年度种植作物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiCropY wiCropY)
    {
        log.info("修改年度种植作物 ========== " + wiCropY.toString());
        return toAjax(wiCropYService.updateWiCropY(wiCropY));
    }

    /**
     * 删除年度种植作物
     */
    @RequiresPermissions("distribute:WiCropY:remove")
    @Log(title = "年度种植作物", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wiCropYService.deleteWiCropYByCropYrs(ids));
    }
}
